//
//  YKTabBarController.m
//  百思不得姐
//
//  Created by Eric.Wu on 16/2/24.
//  Copyright © 2016年 Eric.Wu. All rights reserved.
//

#import "YKTabBarController.h"
#import "YKBSViewController.h"
#import "YKEssenseController.h"
#import "YKFriendThrendsController.h"
#import "YKMeController.h"
#import "YKNavigationController.h"
#import "YKTabBar.h"
@interface YKTabBarController ()

@end

@implementation YKTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    设置tabBar控制器
    YKEssenseController *essense = [[YKEssenseController alloc] init];
    [self addOneChildViewController:essense title:@"精华" imageName:@"tabBar_essence_icon" selectImageName:@"tabBar_essence_click_icon"];
    YKBSViewController *bs = [[YKBSViewController alloc] init];
    [self addOneChildViewController:bs title:@"新帖" imageName:@"tabBar_new_icon" selectImageName:@"tabBar_new_click_icon"];
    
    
    YKFriendThrendsController *FriendThrends = [[YKFriendThrendsController alloc] init];
    [self addOneChildViewController:FriendThrends title:@"关注" imageName:@"tabBar_friendTrends_icon" selectImageName:@"tabBar_friendTrends_click_icon"];
    

    YKMeController *me = [[YKMeController alloc] init];
    [self addOneChildViewController:me title:@"我" imageName:@"tabBar_me_icon" selectImageName:@"tabBar_me_click_icon"];
    
    YKTabBar *tabBar = [[YKTabBar alloc] init];
    
    tabBar.backgroundImage = [UIImage imageNamed:@"tabbar-light"];
    // 替换tabbar
    [self setValue:tabBar forKeyPath:@"tabBar"];
    

}

#pragma mark - 设置子控制器

- (void)addOneChildViewController:(UIViewController *)vc title:(NSString *)title imageName:(NSString *)imageName selectImageName:(NSString *)selectImageName
{
    vc.tabBarItem.title = title;
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor grayColor];
    dict[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    
    NSMutableDictionary *selDict = [NSMutableDictionary dictionary];
    selDict[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:dict forState:UIControlStateNormal];
    [item setTitleTextAttributes:selDict forState:UIControlStateSelected];
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    UIImage *selectImage = [UIImage imageNamed:selectImageName];
    selectImage = [selectImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = selectImage;
    YKNavigationController *nav = [[YKNavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:nav];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
